/**
 * Created by root on 17-4-10.
 */
var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '123456',
    database: 'paperadmin'
});

connection.connect();
// connection.query('select * from userinfo', function (err, rows, fields) {
//     rows.forEach(function (item) {
//         for(var key in item) {
//             console.log(key + ': ' +item[key]);
//         }
//     })
// });

//insert
// var userAddSql = 'insert into userinfo(username, password) values(?, ?)';
// var userAddSql_Params = ['admin12', '1234567ewqs'];
// connection.query(userAddSql, userAddSql_Params, function (err, result) {
//     if(err) {
//         console.log('INSERT ERROR: ' + err.message);
//         return;
//     }
//
//     console.log('--------INSERT---------');
//     for(var key in result) {
//         console.log(key + ': ' + result[key]);
//     }
// });

// update
// var userModSql = 'update userinfo set username = ? where id = 5';
// var update_param = ['ad'];
// connection.query(userModSql, update_param, function (err, result) {
//     if(err) {
//         console.log('INSERT ERROR: ' + err.message);
//         return;
//     }
//
//     console.log('--------INSERT---------');
//     for(var key in result) {
//         console.log(key + ': ' + result[key]);
//     }
// });

// delete
var userDelSql = 'delete from userinfo where id > ?';
var userDel_param = [1];
connection.query(userDelSql, userDel_param, function (err, result) {
    if(err) {
        console.log('INSERT ERROR: ' + err.message);
        return;
    }

    console.log('--------INSERT---------');
    for(var key in result) {
        console.log(key + ': ' + result[key]);
    }
});
connection.end();